package com.example.pushup;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;

public class SettingActivity extends Activity implements OnCheckedChangeListener{
	
	RadioGroup	  radioGroup;
	RadioButton   r_level_1;
	RadioButton   r_level_2;
	RadioButton   r_level_3;
	RadioButton   r_level_4;
	RadioButton   r_level_5;
	EditText	  edittext;
	Button		  okayBt;
	Button		  cancleBt;
	
	RatingBar	  rating;
	int 		  f_LvRating=0;
	int			  restSec=0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);
		
		radioGroup = (RadioGroup)findViewById(R.id.radioGroup);
		r_level_1 = (RadioButton)findViewById(R.id.radio_level1);
		r_level_2 = (RadioButton)findViewById(R.id.radio_level2);
		r_level_3 = (RadioButton)findViewById(R.id.radio_level3);
		r_level_4 = (RadioButton)findViewById(R.id.radio_level4);
		r_level_5 = (RadioButton)findViewById(R.id.radio_level5);
		radioGroup.setOnCheckedChangeListener((OnCheckedChangeListener) this);
		
		edittext = (EditText)findViewById(R.id.input_time);
		okayBt	 = (Button)findViewById(R.id.okayButton);
		cancleBt = (Button)findViewById(R.id.cancleButton);

		
		okayBt.setOnClickListener(new OnClickListener(){
			public void onClick(View v){
				if(edittext.getText().toString() != null)
				{
					restSec = Integer.parseInt(edittext.getText().toString());
					Intent intent = new Intent(SettingActivity.this, ExerciseActivity.class);
					intent.putExtra("LEVEL", f_LvRating);
					intent.putExtra("RESTTIME", restSec);
					startActivity(intent);
					
				} else
				{
					Toast.makeText(getApplicationContext(), "Insert  Sec !", Toast.LENGTH_SHORT).show();
					edittext.requestFocus();
				}
			}
		});
		
		cancleBt.setOnClickListener(new OnClickListener(){
			public void onClick(View v){
				Intent intent = new Intent(SettingActivity.this, MenuActivity.class);
				startActivity(intent);
			}
		});
		
		
		rating = (RatingBar) findViewById(R.id.level_rating);
		rating.setStepSize((float)1.0);
		rating.setRating((float)0);
		rating.setIsIndicator(true);
		
		rating.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
	    public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser)
	         {
	            
	         }
	      }
	      );
				
	}
	
	
	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		if (radioGroup.getCheckedRadioButtonId() == R.id.radio_level1) {
			Toast.makeText(getApplicationContext(),  "Check Level 1", 1).show();
			f_LvRating = 1;
			rating.setProgress(f_LvRating);
		} else if (radioGroup.getCheckedRadioButtonId() == R.id.radio_level2) {
			Toast.makeText(getApplicationContext(),  "Check Level 2", 1).show();
			f_LvRating = 2;
			rating.setProgress(f_LvRating);
		} else if (radioGroup.getCheckedRadioButtonId() == R.id.radio_level3) {
			Toast.makeText(getApplicationContext(),  "Check Level 3", 1).show();
			f_LvRating = 3;
			rating.setProgress(f_LvRating);
		} else if (radioGroup.getCheckedRadioButtonId() == R.id.radio_level4) {
			Toast.makeText(getApplicationContext(),  "Check Level 4", 1).show();
			f_LvRating = 4;
			rating.setProgress(f_LvRating);
		} else {
			Toast.makeText(getApplicationContext(),  "Check Level 5", 1).show();
			f_LvRating = 5;
			rating.setProgress(f_LvRating);
		}
		 
		
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
}
